<?php if (!defined('THINK_PATH')) exit();?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8;" />
<script type="text/javascript" src="/dqchat/Public/js/jquery-1.11.0.min.js" ></script>
<link href="/dqchat/Public/css/myaccount/style.css" type="text/css" rel="stylesheet"></link>
<style>
.active{background:url(/dqchat/Public/img/myaccount_line1.jpg) no-repeat 0 0;}
.header_menu .menu_line {width:80px; height:1px; background:#fff; position:absolute;bottom:-1px;_left:-10px;}
.regift_box1.regift_show {display:block;}
.m2yw_tab { background: url(/dqchat/Public/img/m2line.jpg) repeat-x scroll left bottom transparent; height: 26px; background-color:#dee3e7}
.m2yw_tab ul li {cursor:pointer;color:#78797a;border:1px solid #b1b6ba;border-bottom:none;float: left; height: 22px; line-height: 22px; margin-right: 5px; text-align: center; width: 85px;margin-top:2px }
.m2yw_tab ul .m2yw_cutli {background:#e9ecf3;border-top:2px solid #686a7a;font-weight: bold;}
.m2yw_tab ul .m2yw_cutli.menu_hover {border-bottom:1px solid #959595;background-color:#e9ecf3;}
.pageItem{cursor:pointer;padding-top:5px;}
.regift_box2 td{border-left:1px solid #b1b6ba;border-top:1px solid #b1b6ba}
.pageItem1{padding-top:5px;}
#page{padding-left:25px;}

</style>
<script>
function changeTab(m,n){
   var menu=document.getElementById("tab"+m).getElementsByTagName("li");  
   for(i=0;i<menu.length;i++)
    {
        menu[i].className=i==(n-1)?"m2yw_cutli":"";
    }
} 

</script>
<script>
$(function(){
//回车点击
function test(name){
            $(this).css("font-weight","bold");
            cate = $(".active").attr('name');
            nowpage = $("#current").text();
			nowpage=parseInt(nowpage);
			totalpage = $("#total").val(); 
			totalpage=parseInt(totalpage);
			if(name=="first"){
				var realNowpage=1;
	         }
			if(name=="befor"){
			   var realNowpage = nowpage-1;
			   
			}
			if(name=="next"){
				var realNowpage = nowpage+1;
			}
			if(name=="last"){
				var realNowpage = totalpage;
			}			

		
		if(realNowpage==1){ 	
					$("#beforpage").hide();
					$(".befor").show();
					$("#firstpage").hide();
					$(".first").show();
					$("#nextpage").show();
					$(".next").hide();
					$("#lastpage").show();
					$(".last").hide();
		}else if(realNowpage>=totalpage){	
					$("#beforpage").show();
					$(".befor").hide();
					$("#firstpage").show();
					$(".first").hide();
					$("#nextpage").hide();
					$(".next").show();
					$("#lastpage").hide();
					$(".last").show();						

		}else{		
					$("#beforpage").show();
					$(".befor").hide();
					$("#firstpage").show();
					$(".first").hide();
					$("#nextpage").show();
					$(".next").hide();
					$("#lastpage").show();
					$(".last").hide();
}
			$("#current").text(realNowpage);			
			$('.pageItem').css('font-weight','normal');
			$(this).css("font-weight","bold");
			$.ajax({
            type: "POST",
            url: "<?php echo U('Home/MyAccount/navi');?>",
			data: {cate:cate,page:realNowpage},
			dataType: "text",
            success: function(data){
			$('.regift_menu tr:gt(0)').remove();
			var obj  = eval(data);
			var html ="";
			if(obj.length>0){
				if(cate=="receive"){
			            for(i=0;i<obj.length;i++){
													if(!obj[i]['calias']){
							obj[i]['calias'] = '-';
							}
						html = html+"<tr class=\"regift_line2\"><td>"+obj[i]['cgiftname']+"</td><td>"+obj[i]['ncount']+"</td><td title=\""+obj[i]['calias']+"\">"+obj[i]['cut']+"</td><td>"+obj[i]['nuserid']+"</td><td>"+obj[i]['dtime']+"</td></tr>";
					}
				}else{
					for(i=0;i<obj.length;i++){
						if(!obj[i]['calias']){
							obj[i]['calias'] = '-';
							}
						html = html+"<tr class=\"regift_line2\"><td>"+obj[i]['cgiftname']+"</td><td>"+obj[i]['ncount']+"</td><td title=\""+obj[i]['calias']+"\">"+obj[i]['calias']+"</td><td>"+obj[i]['nbuddyid']+"</td><td>"+obj[i]['dtime']+"</td></tr>";
					}				
				}
				if(obj.length<5){
				for(j=0;j<(5-obj.length);j++){
					html=html+"<tr class=\"regift_line2\"><td  style=\"color:#f0f5fa\">.</td><td  style=\"color:#f0f5fa\">.</td><td  style=\"color:#f0f5fa\">.</td><td  style=\"color:#f0f5fa\">.</td><td  style=\"color:#f0f5fa\">.</td></tr>"
					}
					}
				}
					$('.regift_menu').append(html);
			}
			})
	}
$("#firstpage").click(function(){test('first');});
$("#beforpage").click(function(){test('befor');});
$("#nextpage") .click(function(){test('next');});
$("#lastpage") .click(function(){test('last');});	

	$(document).keypress(function(e){
	    var key = e.which;
			if (key == 13){    //keyCode=13是回车键
			    $(".mywe_button").trigger("click");
						}
	});
//表单的验证
	$(".mywe_button").click(function(){
            money = $('.mywe_text').val();
			if(money!=''){		
				if(isNaN(money) || money==0||money<0){
					alert("请输入有效数字");
					return false;
				}else{	
					money = parseInt(money);
					giftmoney = parseInt($('.mywe_giftmoney').text());
					if(money>giftmoney){
					  alert('超出兑换额度');
					return false;
					}
				}				
			}else {
				alert("请输入兑换额度");
					return false;
					}
  $.ajax({
             type: "POST",
             url: "<?php echo U('Home/MyAccount/oper');?>",
			 data: {money:money},
			 dataType: "text",
             success: function(data){
				message = '';
				if(data==1){
					message = "兑换成功";
					window.location.href="<?php echo U('index');?>"
            }else if(data==2){
					message="兑换失败，请联系客服";	
					
					}
				alert(message);
				window.location.href="dqktv://updatemoney";
				 }
								
			})
    });
	$(".mywe_button1").click(function(){
	if(!confirm("确定要全部兑换")){
	return false;
	};
	money=$(".mywe_giftmoney").text();
	
	if(money!=''){		
				if(isNaN(money) || money==0||money<0){
					alert("您的礼金不足");
					return false;
				}}
	$.ajax({
             type: "POST",
             url: "<?php echo U('Home/MyAccount/oper');?>",
			 data: {money:money},
			 dataType: "text",
             success: function(data){
				message = '';
				if(data==1){
					message = "兑换成功";
					window.location.href="<?php echo U('index');?>"
            }else if(data==2){
					message="兑换失败，请联系客服";	
					
					}
				alert(message);
				window.location.href="dqktv://updatemoney";
				 }
			})
	});
	$('.navItem').hover(function(){
        if(!$(this).hasClass('m2yw_cutli')){

		$(this).addClass('menu_hover');	

	}
      },function(){
		if(!$(this).hasClass('m2yw_cutli')){		
			$(this).removeClass('menu_hover');
    }	
	})
	$('.navItem:eq(0)').click(function(){
	    $('.regift_box1').addClass('regift_show');
		$('.regift_box2').css('display','none');
	})
    $('.navItem:gt(0)').click(function(){
		$("#beforpage").hide();
		$(".befor").show();
		$("#firstpage").hide();
		$(".first").show();
		$("#nextpage").show();
		$(".next").hide();
		$("#lastpage").show();
		$(".last").hide();	
		$('#current').text('1');
		$('.navItem').removeClass('active');
		$(this).addClass('active');	
		index = $('.navItem').index($(this));
		$('.regift_box1').removeClass('regift_show');
		$('.regift_box2').css('display','block');	
	    cate = $(this).attr('name');
		$.ajax({
            type: "POST",
            url: "<?php echo U('Home/MyAccount/navi');?>",
			data: {cate:cate,page:1},
			dataType: "text",
            success: function(data){
			var obj  = eval(data);
		     if(cate=="receive"){
			 	html="<tr class=\"regift_line1\"><td class=\"regift_gfname\">礼物名称</td><td class=\"regift_number\">数量</td><td class=\"regift_name\">送礼人昵称</td><td class=\"regift_ID\">送礼人ID</td><td class=\"regift_time\">赠送时间</td></tr>";
			 }else{
			    html="<tr class=\"regift_line1\"><td class=\"regift_gfname\">礼物名称</td><td class=\"regift_number\">数量</td><td class=\"regift_name\">收礼人昵称</td><td class=\"regift_ID\">收礼人ID</td><td class=\"regift_time\">赠送时间</td></tr>";
			 }
			$('.regift_menu tr').remove();
			$('#page').html("");
				
			if(obj.length>0){
				var totalpage = obj[obj.length-1]['totalPage'];//所有的页数			
				$('#totalWrap').html("");				
				$('#totalWrap').append("<from><input id=\"total\" value="+totalpage+" type=\"hidden\" /></from>");
				var nowpage   = obj[obj.length-1]['nowPage'];//当前的页数
			    li = "";
				if(cate=="receive"){
				            menu=1;
						    var firstPage=1;         //首页
						    var lastPage =totalpage; //尾页
						    li = li+"<li class=\"pageItem1\">第 <span id=\"current\">1</span>  页</li>";
						    li = li+"<li class=\"pageItem1\" >共 "+totalpage+" 页</li>";					 
				            for(i=0;i<obj.length;i++){
							if(!obj[i]['calias']){
							obj[i]['calias'] = '-';
							}
							html = html+"<tr class=\"regift_line2\"><td>"+obj[i]['cgiftname']+"</td><td>"+obj[i]['ncount']+"</td><td title=\""+obj[i]['calias']+"\">"+obj[i]['calias']+"</td><td>"+obj[i]['nuserid']+"</td><td>"+obj[i]['dtime']+"</td></tr>";
						}
					}else{
					        menu=1;
						    var firstPage=1;         //首页
						    var lastPage =totalpage; //尾页
						   li = li+"<li class=\"pageItem1\">第 <span id=\"current\">1</span>  页</li>";
						   li = li+"<li class=\"pageItem1\" >共 "+totalpage+" 页</li>";
						for(i=0;i<obj.length;i++){
							if(!obj[i]['calias']){
							obj[i]['calias'] = '-';
							}
						    html = html+"<tr class=\"regift_line2\"><td>"+obj[i]['cgiftname']+"</td><td>"+obj[i]['ncount']+"</td><td title=\""+obj[i]['calias']+"\">"+obj[i]['calias']+"</td><td>"+obj[i]['nbuddyid']+"</td><td>"+obj[i]['dtime']+"</td></tr>";
						}	
                					
				}
				if(obj.length<5){
					for(j=0;j<(5-obj.length);j++){
						html=html+"<tr class=\"regift_line2\"><td  style=\"color:#f0f5fa\">.</td><td  style=\"color:#f0f5fa\">.</td><td  style=\"color:#f0f5fa\">.</td><td  style=\"color:#f0f5fa\">.</td><td  style=\"color:#f0f5fa\">.</td></tr>"
						}					
				}
				$('#page').append(li);	
				$('.regift_menu2').css('display','show'); 
				}else{
					for(j=0;j<5;j++){
						html=html+"<tr class=\"regift_line2\"><td  style=\"color:#f0f5fa\">.</td><td  style=\"color:#f0f5fa\">.</td><td  style=\"color:#f0f5fa\">.</td><td  style=\"color:#f0f5fa\">.</td><td  style=\"color:#f0f5fa\">.</td></tr>"
						}
						li="";
					li = li+"<li class=\"pageItem1\">第 <span id=\"current\">1</span>  页</li>";
					li = li+"<li class=\"pageItem1\" >共 1 页</li>";	
                    $("#beforpage").hide();
		            $(".befor").show();
		            $("#firstpage").hide();
					$(".first").show();
					$("#nextpage").hide();
					$(".next").show();
					$("#lastpage").hide();
					$(".last").show();	
                    $('#page').append(li);						
					} 
					
					$('.regift_menu').append(html);
			if(totalpage<=1){			
					$("#beforpage").hide();
					$(".befor").show();
					$("#firstpage").hide();
					$(".first").show();
					$("#nextpage").hide();
					$(".next").show();
					$("#lastpage").hide();
					$(".last").show();	
}	
			}
			})
	});
	
})
</script>
</head>
<body style="background:#e9ecf3;">

<div id="box">

		<div class="m2yw_tab">
		    <ul id="tab2">
				<li style="margin-left:10px;" class="navItem m2yw_cutli" onclick="changeTab(2,1)" id="navItem1">我的财富</li>
				<li class="navItem" name="receive" onclick="changeTab(2,2)">收到礼物</li> 
				<li class="navItem" name="send" onclick="changeTab(2,3)">送出礼物</li>  
		    </ul>
		</div>	
	<div class="regift_box1 regift_show">
		    
				<div class="mywe_menu1">
					 <ul> 
						 <li>金币：<?php echo ($money); ?></li>
						 <li class="mywe_money">礼金：<span class="mywe_giftmoney"><?php echo ($giftmoney); ?></span></li>
					 </ul>
				</div >
				<div class="mywe_menu2">
					<form>
					<input type="hidden" id="currentH" value="1" />
					<p>礼金兑换虚拟货币</p>
						 <ul class="mywe_detitle">							 
							 <li><input type="text" class="mywe_text" name="money"  /></li>
							 <li><div class="mywe_button" >兑换</div></li>
							 <li><div class="mywe_button1" >全部兑换</div></li>
						 </ul>
					</form>
				</div>
		</div>
	<div class="regift_box2">
	
		<table class="regift_menu" cellspacing=0 cellpadding=0>
            
        </table>
		<div class="regift_menu2">
		   <div id="page">
		   </div>
		    <ul >
			
			<li id="firstpage" class="pageItem" name="first">首页</li>
			<li class="first" style="display:none;margin-top:5px">首页</li>
			<li id="beforpage" class="pageItem" name="befor">上一页</li>
			<li  class="befor" style="display:none;margin-top:5px">上一页</li>
			<li id="nextpage"  class="pageItem" name="next">下一页</li>
			<li  class="next" style="display:none;margin-top:5px">下一页</li>
			<li id="lastpage"  class="pageItem" name="last">尾页</li> 
			<li  class="last" style="display:none;margin-top:5px">尾页</li>			
			</ul>
		</div> 
	</div> 
 
</div>
<div id="totalWrap"></div>
</body>
</html>